﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections.Specialized;

namespace IronCow.UnitTests.Mock
{
    public abstract class MockResponsePart : ICollection<MockResponsePart>
    {
        public MockResponsePartCollection NestedParts { get; private set; }

        protected MockResponsePart()
        {
            NestedParts = new MockResponsePartCollection();
        }

        public abstract void GetResponseMarkup(XmlWriter markupWriter, Dictionary<string, string> parameters);

		protected virtual void GetNestedResponseMarkup(XmlWriter markupWriter, Dictionary<string, string> parameters)
        {
            foreach (var nestedPart in NestedParts)
            {
                nestedPart.GetResponseMarkup(markupWriter, parameters);
            }
        }

        #region ICollection<MockResponsePart> Members

        public void Add(MockResponsePart item)
        {
            NestedParts.Add(item);
        }

        public void Clear()
        {
            NestedParts.Clear();
        }

        public bool Contains(MockResponsePart item)
        {
            return NestedParts.Contains(item);
        }

        public void CopyTo(MockResponsePart[] array, int arrayIndex)
        {
            NestedParts.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return NestedParts.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(MockResponsePart item)
        {
            return NestedParts.Remove(item);
        }

        #endregion

        #region IEnumerable<MockResponsePart> Members

        public IEnumerator<MockResponsePart> GetEnumerator()
        {
            return NestedParts.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return NestedParts.GetEnumerator();
        }

        #endregion
    }
}
